package com.kbbywyclient.ui.pop;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.PopupWindow;

import com.kbbywyclient.R;
import com.kbbywyclient.callback.RecyclerItemClickedListener;
import com.kbbywyclient.ui.adapter.base.BaseAdapter;
import com.kbbywyclient.widget.divider.VerticalItemDecoration;

import java.util.List;

/**
 * Created by Jiangzx on 2017/10/30 15:39.
 */

public class PureListPop<T> extends PopupWindow {

    public PureListPop(@NonNull Context context,
                       @NonNull List<T> data,
                       @NonNull final RecyclerItemClickedListener<T> listener){
        RecyclerView recyclerView=new RecyclerView(context);
        recyclerView.setLayoutParams(
                new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.MATCH_PARENT));
        LinearLayoutManager layoutManager=
                new LinearLayoutManager(context,LinearLayoutManager.VERTICAL,false);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.addItemDecoration(new VerticalItemDecoration(0XFFDDDDDD,1));
        BaseAdapter<T> adapter=new BaseAdapter<T>(data,R.layout.item_pure_list_text) {
            @Override
            public void convert(Holder holder, T t, int position) {
                holder.setText(R.id.tv_text,t.toString());
                holder.itemView.setOnClickListener(v->listener.onItemClicked(t));
            }
        };
        recyclerView.setAdapter(adapter);
        setContentView(recyclerView);
        setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
        setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
        setBackgroundDrawable(ContextCompat.getDrawable(context,
                R.drawable.shape_corner_3dp_stroke_1px_ddd_solid_fff));
        setAnimationStyle(R.style.TopScaleInAlphaOut);
        setFocusable(true);
    }
}
